package com.sxbbc.common.basics.rest;

/**
 * 
 * rest
 * @author Wahyee
 */
public class RestFactory {
	
	private static final String DEFAULT_DATA = "";
	private static final String DEFAULT_SUCCESS_CODE = "0"; 
	private static final String DEFAULT_SUCCESS_MSG = "OK";
	private static final String DEFAULT_FAIL_CODE = "10000";
	private static final long DEFAULT_COUNT = 0;
	
	private RestFactory() {}
	
	public static RestResponse success() {
		return new RestResponse(DEFAULT_SUCCESS_CODE,DEFAULT_SUCCESS_MSG,DEFAULT_DATA,DEFAULT_COUNT);
	}
	
	public static RestResponse success(Object data) {
		return new RestResponse(DEFAULT_SUCCESS_CODE,DEFAULT_SUCCESS_MSG,data,DEFAULT_COUNT);
	}
	
	public static RestResponse success(Object data, long count) {
		return new RestResponse(DEFAULT_SUCCESS_CODE,DEFAULT_SUCCESS_MSG,data,count);
	}
	
	public static RestResponse success(String msg) {
		return new RestResponse(DEFAULT_SUCCESS_CODE,msg,DEFAULT_DATA,DEFAULT_COUNT);
	}
	
	public static RestResponse success(String msg,Object data) {
		return new RestResponse(DEFAULT_SUCCESS_CODE,msg,data,DEFAULT_COUNT);
	}
	
	public static RestResponse fail(String msg) {
		return new RestResponse(DEFAULT_FAIL_CODE,msg,DEFAULT_DATA,DEFAULT_COUNT); 
	}
	
	public static RestResponse fail(String code,String msg) {
		return new RestResponse(code,msg,DEFAULT_DATA,DEFAULT_COUNT); 
	}
	
	public static RestResponse fail(String code,String msg,long count) {
		return new RestResponse(code,msg,DEFAULT_DATA,count); 
	}
	
	public static RestResponse  getInstance(String code,String msg,Object data) {
		return new RestResponse(code, msg, data,DEFAULT_COUNT);
	}
	
	/**
	 * 
	 * 根据状态返回
	 * @param b 状态
	 * @param msgt 正确时的返回信息
	 * @param msgf 错误时的返回信息
	 * @author Wahyee
	 */
	public static RestResponse center(boolean b ,String msgt,String msgf) {
		if(b) {
			return success(msgt);
		}else {
			return fail(msgf);
		}
	}
}
